package service;

import com.google.gson.Gson;
import model.Response;
import util.HttpUtils;

import java.io.IOException;
import java.net.URLEncoder;

public class OkyRobotServiceImpl implements RobotService {
    public static final String apiTpl = "http://api.qingyunke.com/api.php?key=free&appid=0&msg=%s";
    public static final Gson gson = new Gson();

    @Override
    public Response qa(String msg) throws IOException {
        String api = String.format(apiTpl, URLEncoder.encode(msg, "UTF-8"));
        String result = HttpUtils.request(api);
        Response response = gson.fromJson(result, Response.class);
        return response;
    }
}
